package com.rem.photoablum.dao;

import com.rem.photoablum.model.Photo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author remembrance
 * @version 1.0
 * @date 2022/3/6 21:38
 */
public interface PhotoDao extends JpaRepository<Photo,Long> {
     @Transactional
     @Modifying
     @Query(value = "insert into p_photo(id,pid,aid,url) values(?1,?2,?3,?4) ",nativeQuery = true)
     int addPhoto(Long id,Integer pid,Long aid, String url);

     @Transactional
     int deleteAllByPid(Integer pid);

     @Transactional
     int deleteAllByAid(Long aid);

     List<Photo> findAllByPid(Integer pid);

     List<Photo> findAllByAid(Long aid);



}
